/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.losalpes.catalogo.servicios;

import com.losalpes.catalogo.excepciones.InvalidDataException;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author amocampo
 */
@Stateless
public class ReportServicesBean implements ReportServicesBeanRemote, ReportServicesBeanLocal {
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method" or "Web Service > Add Operation")

    /**
     * Unidad de persistencia de la aplicacion
     */
    @PersistenceContext
    EntityManager em;

    public List reportRegistroVentaByDateRange(Date begin, Date end) throws InvalidDataException {
        try {
            Query query = em.createNativeQuery("RegistroVenta.findByDateRange");
            query.setParameter("fechaInicio", begin);
            query.setParameter("fechaFin", end);
            return query.getResultList();
        }
        catch (Exception e) {
            throw new InvalidDataException("ReportServicesBeanBean:reportRegistroVentaByDateRange: " + e.toString());
        }
    }

    public List reportRegistroVentaByUsuario(String documento) throws InvalidDataException {
        try {
            Query query = em.createNamedQuery("RegistroVenta.findByUser");
            query.setParameter("documento", documento);
            return query.getResultList();
        }
        catch (Exception e) {
            throw new InvalidDataException("ReportServicesBeanBean:reportRegistroVentaByUsuario: " + e.toString());
        }
    }
 
}
